package org.sdv.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(
		urlPatterns = {"/calculator/add", "/calc-add"}, 
		initParams = {@WebInitParam(name = "arg1", value = "2"), @WebInitParam(name = "arg2", value = "3")})
public class AddCalculationServlet extends HttpServlet {

	private static final long serialVersionUID = 2489765727514198567L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		out.println("<html><head>");
		out.println("<title>servlet-annotations</title>");
		out.println("</head><body>");		
		out.println("AddCalculationServlet is invoked by <h3>" +
				req.getRequestURI() +
				"</h3> with initparam values: <h3>" +
				getInitParameter("arg1") + "</h3> and <h3>" +
				getInitParameter("arg2") + "</h3>."
		);
		out.println("</body></html>");
	}
}
